package com.sh.ndt.common;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author vivek
 * Utility to build xml string 
 */
public class XmlBuilder {
private String deskXml = "-1";
private String deskName;

    public String getDeskName() {
        return deskName;
    }

    public String getDeskXml() {
        return deskXml;
    }

/**
 * 
 * @param manyDesk 
 * method to separate desk name and desk id 
 * and supply desk id list to xmlBuilder()
 */

public void prepareDesk(List<String> manyDesk) {
      if (manyDesk != null) {
            List<String> deskId = new ArrayList<String>();

            String name = null;


            String[] deskArray;

            for (int i = 0; i < manyDesk.size(); i++) {
                String val = manyDesk.get(i);
                deskArray = val.split("-");
                deskId.add(deskArray[0]);
                if (name == null) {
                    name = deskArray[1];
                } else {
                    name = name + ", " + deskArray[1];
                }
            }
            buildXml(deskId);
            deskName = name;
    }
}
/**
 * method to build xml String 
 * using list of String values(IDs)
 */
public void buildXml (List<String> stringList) {
    if(stringList != null) {
     
    String xml = "<?xml version=\"1.0\"?><RESULTSET>";
    for(int i = 0; i < stringList.size(); i++) {
        xml = xml + "<ITEM><ID>" + stringList.get(i) + "</ID></ITEM>";
    }
    xml = xml + "</RESULTSET>";   
    this.deskXml = xml;
    }
}
}
